home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpc09905c.lha / fpc / units / sysamiga.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-21  |  56KB  |  1,876 lines

  1. {
  2.     $Id: sysamiga.pas,v 1.9 1998/08/17 12:34:22 carl Exp $
  3.     This file is part of the Free Pascal run time library.
  4.     Copyright (c) 1993,98 by Carl Eric Codere
  5.     Some parts taken from
  6.        Marcel Timmermans - Modula 2 Compiler
  7.        Nils Sjoholm - Amiga porter
  8.        Matthew Dillon - Dice C (with his kind permission)
  9.           dillon@backplane.com
  10.  
  11.     See the file COPYING.FPC, included in this distribution,
  12.     for details about the copyright.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.  
  18.  **********************************************************************}
  19. unit sysamiga;
  20.  
  21. {--------------------------------------------------------------------}
  22. { LEFT TO DO:                                                        }
  23. {--------------------------------------------------------------------}
  24. { o GetDir with different drive numbers                              }
  25. {--------------------------------------------------------------------}
  26.  
  27. {$I os.inc}
  28.  
  29. { AmigaOS uses character #10 as eoln only }
  30. {$DEFINE SHORT_LINEBREAK}
  31.  
  32.   interface
  33.  
  34.     { used for single computations }
  35.     const BIAS4 = $7f-1;
  36.  
  37.     {$I systemh.inc}
  38.  
  39.     {$I heaph.inc}
  40.  
  41. const
  42.   UnusedHandle    : longint = -1;
  43.   StdInputHandle  : longint = 0;
  44.   StdOutputHandle : longint = 0;
  45.   StdErrorHandle  : longint = 0;
  46.  
  47.  _ExecBase:longint = $4;
  48.  _WorkbenchMsg : longint = 0;
  49.  
  50.  _IntuitionBase : pointer = nil;       { intuition library pointer }
  51.  _DosBase       : pointer = nil;       { DOS library pointer       }
  52.  _UtilityBase   : pointer = nil;       { utiity library pointer    }
  53.  
  54.  { Required for crt unit }
  55.   function do_read(h,addr,len : longint) : longint;
  56.   function do_write(h,addr,len : longint) : longint;
  57.  
  58.  
  59.  
  60.  
  61.  
  62.   implementation
  63.  
  64.  const
  65.  
  66.    intuitionname : pchar = 'intuition.library';
  67.    dosname : pchar = 'dos.library';
  68.    utilityname : pchar = 'utility.library';
  69.    argc : longint = 0;
  70.    { AmigaOS does not autoamtically deallocate memory on program termination }
  71.    { therefore we have to handle this manually. This is a list of allocated  }
  72.    { pointers from the OS, we cannot use a linked list, because the linked   }
  73.    { list itself uses the HEAP!                                              }
  74.    pointerlist : array[1..8] of longint =
  75.     (0,0,0,0,0,0,0,0);
  76.  
  77.  
  78.     {$I exec.inc}
  79.  
  80.   TYPE
  81.     TDateStamp = packed record
  82.         ds_Days         : Longint;      { Number of days since Jan. 1, 1978 }
  83.         ds_Minute       : Longint;      { Number of minutes past midnight }
  84.         ds_Tick         : Longint;      { Number of ticks past minute }
  85.     end;
  86.     PDateStamp = ^TDateStamp;
  87.  
  88.  
  89.     PFileInfoBlock = ^TfileInfoBlock;
  90.     TFileInfoBlock = packed record
  91.         fib_DiskKey     : Longint;
  92.         fib_DirEntryType : Longint;
  93.                         { Type of Directory. If < 0, then a plain file.
  94.                           If > 0 a directory }
  95.         fib_FileName    : Array [0..107] of Char;
  96.                         { Null terminated. Max 30 chars used for now }
  97.         fib_Protection  : Longint;
  98.                         { bit mask of protection, rwxd are 3-0. }
  99.         fib_EntryType   : Longint;
  100.         fib_Size        : Longint;      { Number of bytes in file }
  101.         fib_NumBlocks   : Longint;      { Number of blocks in file }
  102.         fib_Date        : TDateStamp; { Date file last changed }
  103.         fib_Comment     : Array [0..79] of Char;
  104.                         { Null terminated comment associated with file }
  105.         fib_Reserved    : Array [0..35] of Char;
  106.     end;
  107.  
  108.  
  109.     TProcess = packed record
  110.         pr_Task         : TTask;
  111.         pr_MsgPort      : TMsgPort;      { This is BPTR address from DOS functions  }
  112. {126}   pr_Pad          : Word;         { Remaining variables on 4 byte boundaries }
  113. {128}   pr_SegList      : Pointer;      { Array of seg lists used by this process  }
  114. {132}   pr_StackSize    : Longint;      { Size of process stack in bytes            }
  115. {136}   pr_GlobVec      : Pointer;      { Global vector for this process (BCPL)    }
  116. {140}   pr_TaskNum      : Longint;      { CLI task number of zero if not a CLI      }
  117. {144}   pr_StackBase    : BPTR;         { Ptr to high memory end of process stack  }
  118. {148}   pr_Result2      : Longint;      { Value of secondary result from last call }
  119. {152}   pr_CurrentDir   : BPTR;         { Lock associated with current directory   }
  120. {156}   pr_CIS          : BPTR;         { Current CLI Input Stream                  }
  121. {160}   pr_COS          : BPTR;         { Current CLI Output Stream                 }
  122. {164}   pr_ConsoleTask  : Pointer;      { Console handler process for current window}
  123. {168}   pr_FileSystemTask : Pointer;    { File handler process for current drive   }
  124. {172}   pr_CLI          : BPTR;         { pointer to ConsoleLineInterpreter         }
  125.         pr_ReturnAddr   : Pointer;      { pointer to previous stack frame           }
  126.         pr_PktWait      : Pointer;      { Function to be called when awaiting msg  }
  127.         pr_WindowPtr    : Pointer;      { Window for error printing }
  128.         { following definitions are new with 2.0 }
  129.         pr_HomeDir      : BPTR;         { Home directory of executing program      }
  130.         pr_Flags        : Longint;      { flags telling dos about process          }
  131.         pr_ExitCode     : Pointer;      { code to call on exit of program OR NULL  }
  132.         pr_ExitData     : Longint;      { Passed as an argument to pr_ExitCode.    }
  133.         pr_Arguments    : PChar;        { Arguments passed to the process at start }
  134.         pr_LocalVars    : TMinList;      { Local environment variables             }
  135.         pr_ShellPrivate : Longint;      { for the use of the current shell         }
  136.         pr_CES          : BPTR;         { Error stream - IF NULL, use pr_COS       }
  137.     end;
  138.     PProcess = ^TProcess;
  139.  
  140.   { AmigaOS does not automatically close opened files on exit back to  }
  141.   { the operating system, therefore as a precuation we close all files }
  142.   { manually on exit.                                                  }
  143.   PFileList = ^TFileList;
  144.   TFileList = record { no packed, must be correctly aligned }
  145.    Handle: longint;      { Handle to file    }
  146.    next: pfilelist;      { Next file in list }
  147.    closed: boolean;      { TRUE=file already closed }
  148.   end;
  149.  
  150.  
  151.  
  152.  
  153.     Const
  154.      CTRL_C               = 20;      { Error code on CTRL-C press }
  155.      SIGBREAKF_CTRL_C     = $1000;   { CTRL-C signal flags }
  156.  
  157.     _LVOFindTask          = -294;
  158.     _LVOWaitPort          = -384;
  159.     _LVOGetMsg            = -372;
  160.     _LVOOpenLibrary       = -552;
  161.     _LVOCloseLibrary      = -414;
  162.     _LVOClose             = -36;
  163.     _LVOOpen              = -30;
  164.     _LVOIoErr             = -132;
  165.     _LVOSeek              = -66;
  166.     _LVODeleteFile        = -72;
  167.     _LVORename            = -78;
  168.     _LVOWrite             = -48;
  169.     _LVORead              = -42;
  170.     _LVOCreateDir         = -120;
  171.     _LVOSetCurrentDirName = -558;
  172.     _LVOGetCurrentDirName = -564;
  173.     _LVOInput             = -54;
  174.     _LVOOutput            = -60;
  175.     _LVOUnLock            = -90;
  176.     _LVOLock              = -84;
  177.     _LVOCurrentDir        = -126;
  178.  
  179.     _LVONameFromLock      = -402;
  180.     _LVONameFromFH        = -408;
  181.     _LVOGetProgramName    = -576;
  182.     _LVOGetProgramDir     = -600;
  183.     _LVODupLock           =  -96;
  184.     _LVOExamine           = -102;
  185.     _LVOParentDir         = -210;
  186.     _LVOSetFileSize       = -456;
  187.     _LVOSetSignal         = -306;
  188.     _LVOAllocVec          = -684;
  189.     _LVOFreeVec           = -690;
  190.  
  191.  
  192.       { Errors from IoErr(), etc. }
  193.       ERROR_NO_FREE_STORE              = 103;
  194.       ERROR_TASK_TABLE_FULL            = 105;
  195.       ERROR_BAD_TEMPLATE               = 114;
  196.       ERROR_BAD_NUMBER                 = 115;
  197.       ERROR_REQUIRED_ARG_MISSING       = 116;
  198.       ERROR_KEY_NEEDS_ARG              = 117;
  199.       ERROR_TOO_MANY_ARGS              = 118;
  200.       ERROR_UNMATCHED_QUOTES           = 119;
  201.       ERROR_LINE_TOO_LONG              = 120;
  202.       ERROR_FILE_NOT_OBJECT            = 121;
  203.       ERROR_INVALID_RESIDENT_LIBRARY   = 122;
  204.       ERROR_NO_DEFAULT_DIR             = 201;
  205.       ERROR_OBJECT_IN